class Solution(object):
    def romanToInt(self, s):
        """
        :type s: str
        :rtype: int
        """
        roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
        x = 0
        i = 0
        while i < len(s) - 1:
            c = s[i]
            if roman[c] < roman[s[i+1]]:
                x -= roman[c]
            else:
                x += roman[c]
            i += 1
        x += roman[s[-1]]
        return x

s = Solution()
r = s.romanToInt("DCXXI")
print(r)
